﻿using System.Windows;
using System.Windows.Forms;
using Microsoft.Win32;
using TextBox = System.Windows.Controls.TextBox;

namespace PrismFactory.SoftwareFactory.Views.CreateSolution
{
    /// <summary>
    /// Interaction logic for CreateSolutionPageWPFView.xaml
    /// </summary>
    public partial class EnsureEntlibAssembliesPathPageView
    {
        public EnsureEntlibAssembliesPathPageView()
        {
            InitializeComponent();
        }

        private void OnEntlibAssembliesButtonClick(object sender, RoutedEventArgs e)
        {
            OpenFolderBrowserDialog("Please select the folder where to find the needed Entlib assemblies.", entlibAssembliesPathText);
        }

        private static void OpenFolderBrowserDialog(string description, TextBox textBox)
        {
            var dlg = new FolderBrowserDialog
                          {
                              Description = description,
                              ShowNewFolderButton = false,
                          };
            if (!string.IsNullOrEmpty(textBox.Text))
            {
                dlg.SelectedPath = textBox.Text;
            }
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                textBox.Text = dlg.SelectedPath;
            }
            dlg.Dispose();
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            entlibAssembliesPathText.Text = (string)Registry.GetValue("HKEY_CURRENT_USER\\Software\\4ward", "DefaultEntlibAssembliesPath", string.Empty);
        }
    }
}